package com.tanhua.server.controller;


import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("/user")
@RestController
public class SettingsController {
    @Autowired
    private SettingsService settingsService;

    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo settingsVo = settingsService.settings();
        return ResponseEntity.ok(settingsVo);
    }

    @PostMapping("/questions")
    public ResponseEntity question(@RequestBody Map map) {
        String content = (String) map.get("content");
        HashMap<Object, Object> resultMap = settingsService.saveQuestion(content);
        return ResponseEntity.ok(resultMap);
    }

    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map) {
        Map<Object, Object> resultMap = settingsService.saveSettings(map);
        return ResponseEntity.ok(resultMap);
    }

    @GetMapping("blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        PageResult pr = settingsService.blacklist(page, size);
        return ResponseEntity.ok(pr);
    }

    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUid) {
        settingsService.deleteBlackList(blackUid);
        return ResponseEntity.ok("删除成功");
    }
}
